import Cookies from 'js-cookie'
const cookieId = "JSESSIONID"
const user = {
    state: {
        id: 1,
        username: "",
        sex: '男',
        name: '',
        email: '',
        phone: '',
        code:'',
        token: Cookies.get(cookieId), // 获取名为 JSESSIONID 的 cookie 数据 作为token使用
        image:''
        // token: Cookies.get('JSESSIONID') // 获取名为 JSESSIONID 的 cookie 数据 作为token使用
    },
    getters: {
        //获取id
        getId(state) {
            return state.id
        },
        getUsername(state){
            return state.username
        },
        getSex(state){
            return state.sex
        },
        getName(state){
            return state.name
        },
        getEmail(state){
            return state.email
        },
        getPhone(state){
            return state.phone
        },
        getCode(state){
            return state.code
        },
        getToken(state) {
            return state.token;
        }
        // getToken(state) {
        //     return this.state.token
        // }
    },
    mutations: {
        //保存id
        saveId(state, id) {
            state.id = id
        },
        saveUser(state,user){
            state.id=user.id
            state.password=user.password
            state.username=user.username
            state.name=user.name
            state.email=user.email
            state.sex=user.sex
            state.phone=user.phone
        },
        saveUsername(state, username){
            state.username = username;
        },
        saveUsernameAndId(state, user) {
            state.id = user.id
            state.username = user.username
        },
        savePhone(state, phone) {
            state.phone = phone;
        },
        saveSex(state, sex) {
            state.sex = sex;
        },
        saveName(state, name) {
            state.name = name;
        },
        saveCode(state, code) {
            state.code = "data:image/jpeg;base64," + code;
        },
        saveEmail(state,email){
            state.email=email;
        },
        removeToken(state) {
            state.token = ''
        },
    },
    actions: {}
}
export default user
